<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="${ctx }/js/plugs/jquery-ui-1.10.3.custom/css/mycss/jquery-ui-1.10.3.custom.css" rel="stylesheet"
          type="text/css"/>
    <title>活动信息</title>
    <link href="${ctx}/js/plugs/validate/jquery.validate.css" type="text/css" rel="stylesheet"/>
    <script src="${ctx}/js/plugs/validate/jquery.validate.js" type="text/javascript"></script>
    <script src="${ctx}/js/plugs/validate/messages_cn.js" type="text/javascript"></script>
    <script src="${ctx }/js/plugs/validate/jquery.metadata.js" type="text/javascript"></script>
    <script type="text/javascript">

        function check() {
            var objFile = document.getElementById("wxQRcodefile");
            if (objFile.value == "") {
                alert("不能空")
            }
            fileSize = objFile.files[0].size;
            var size = fileSize / 1024;
            if (size > 1000) {
                alert("二维码大小需在1MB之内！");
                document.getElementById("wxQRcodefile").value = '';
                return false;
            }
            var id = $('#id').val();
            var url = "/sy/lottery/codeUpload.do?id="+id;
            var form_data = new FormData($('#WxCodeForm')[0]);
            $.ajax({
                url: url,
                data: form_data,
                type: "post",
                processData: false,
                contentType: false,
                success: function (data) {
                    if (data.length==1)
                    {
                        alert("文件上传失败！");
                        document.getElementById("wxQRcodefile").value = '';
                    }else{
                        alert("文件上传成功！");
                        document.getElementById("id").value = data;
                    }
                }
            });
        }
    </script>

    <script type="text/javascript">

        $(document).ready(function () {
            currentMenu("lotterymanager");

            jQuery.validator.addMethod("dateRequired", function (value, element) {
                var date = value;

                if (date == "" || date == null) {
                    return false;
                } else {
                    return true;
                }
                return true;
            }, "日期不能为空");

            jQuery.validator.addMethod("isDateOver", function (value, element) {
                var startTime = $('#startTimeStr').val();
                var endTime = $('#endTimeStr').val();
                if (endTime < startTime) {
                    return false;
                } else {
                    return true;
                }
                return true;
            }, "结束时间不能早于起始时间");

            $("#inputForm").validate({
                rules: {
                    name: {required: true, minlength: 1, maxlength: 50},
                    startTimeStr: {dateRequired: true, dateISO: true},
                    endTimeStr: {dateRequired: true, dateISO: true, isDateOver: true},
                    description: {required: true, minlength: 1, maxlength: 2000}

                }, messages: {
                    startTimeStr: {dateRequired: "日期不能为空"},
                    endTimeStr: {dateRequired: "日期不能为空"},

                },
                errorPlacement: function (error, element) {
                    element.parent().append(error);
                }
            });
        });

        function checkForm() {
            //如果已经设置奖项了,无法保存
            var id = $('#id').val();
            var startFlag = 0;
            var upcode = null;
            if (id == "" || id == null || id == undefined) {
                //PASS
            } else {
                var url = "/sy/lottery/checkActivityStatusAjax.do";
                var data = "id=" + id;
                $.ajax({
                    url: url,
                    data: data,
                    type: "post",
                    success: function (data) {
                        if (data == "1") {
                            startFlag = 1;
                        }
                    }
                });
            }
            if (startFlag == 1) {
                alert("该活动已经有人参加，无法修改");
                return;
            }
            $('#inputForm').submit();
        }
    </script>
    <style type="text/css">
        .ac-input-td input, .ac-input-td select {
            padding: 4px ! important;
            font-size: 14px;
        }

        .red-color {
            color: red;
        }
    </style>
</head>
<body>

<div style="margin-top: 15px;">

</div>
<div style="clear: both;"></div>
<div id="dwBody">
    <div id="dwBodyContent" class="bodyCenter" style="">

        <div id="dwBodyUser">
            <div class="surveyCollectMiddle">
                <div class="surveyCollectMiddleContent">
                    <div style="padding: 25px 45px;overflow: auto;padding-top: 35px;">
                        <div style="border-bottom: 1px solid #DFDFDF;padding: 5px;color: #666565;">活动信息</div>
                        <div style="padding: 5px;color:#666565; ">
                            <form id="WxCodeForm"  method="post"
                                  enctype="multipart/form-data">
                                <table class="ac-form-table">
                                    <tr>
                                        <td width="80" align="right"><span class="red-color">&nbsp;</span>负责人微信二维码
                                        </td>
                                        <td class="ac-input-td">
                                            <input id="wxQRcodefile" type="file" name="wxQRcodefile" onchange="check()"/>
                                            <p style="color:red;font-size: 13px;">
                                                <c:if test="${saveError==null}">请将图片名命名为负责人姓名,且图片大小控制在1MB之内</c:if>
                                                <c:if test="${saveError!=null}">${saveError}</c:if>
                                            </p>
                                        </td>
                                    </tr>
                                </table>
                            </form>

                            <form id="inputForm" action="${ctx }/sy/lottery/save.do" method="post">
                                <input type="hidden" name="id" id="id" value="${entity.id }">
                                <table width="100%">
                                    <tr>
                                        <td valign="top" align="left">
                                            <table class="ac-form-table">
                                                <tr>
                                                    <td width="80" align="right"><span
                                                            class="red-color">*&nbsp;</span>活动名称
                                                    </td>
                                                    <td class="ac-input-td"><input type="text" id="name" name="name"
                                                                                   value="${entity.name }"></td>
                                                </tr>
                                                <tr>
                                                    <td width="80" align="right"><span
                                                            class="red-color">&nbsp;</span>开始时间
                                                    </td>
                                                    <td class="ac-input-td"><input id="startTimeStr" type="date"
                                                                                   name="startTimeStr"
                                                                                   value="${entity.startTimeStr }"/>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td width="80" align="right"><span
                                                            class="red-color">&nbsp;</span>结束时间
                                                    </td>
                                                    <td class="ac-input-td"><input id="endTimeStr" type="date"
                                                                                   name="endTimeStr"
                                                                                   value="${entity.endTimeStr }"/>
                                                    </td>
                                                </tr>

                                                <c:if test="${entity.wxQRcode!=null}">
                                                    <tr>
                                                        <td width="80" align="right"><span
                                                                class="red-color">&nbsp;</span>二维码预览
                                                        </td>
                                                        <td class="ac-input-td">
                                                            <c:if test="${fn:contains(entity.wxQRcode,'png')}">
                                                                <img src="data:image/png;base64,${ImgBase64}"
                                                                     style="width: 85px;height: 80px;"/>
                                                            </c:if>
                                                            <c:if test="${fn:contains(entity.wxQRcode,'jpeg')}">
                                                                <img src="data:image/jpeg;base64,${ImgBase64}"
                                                                     style="width: 85px;height: 80px;"/>
                                                            </c:if>
                                                            <c:if test="${fn:contains(entity.wxQRcode,'jpg')}">
                                                                <img src="data:image/jpg;base64,${ImgBase64}"
                                                                     style="width: 85px;height: 80px;"/>
                                                            </c:if>
                                                        </td>
                                                    </tr>
                                                </c:if>


                                                <tr>
                                                    <td width="80" align="right"><span
                                                            class="red-color">&nbsp;</span>活动规则
                                                    </td>

                                                    <td class="ac-input-td"><textarea id="description" rows="20"
                                                                                      cols="20"
                                                                                      style="width:400px; height:200px"
                                                                                      name="description">${entity.description }</textarea>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>

                                    <tr>
                                        <td height="50">
                                            <input type="button" value="${empty(entity.id) ? '新建':'保存修改'}"
                                                   class="sbtn25 sbtn25_1" style="margin-left: 125px;"
                                                   onclick="checkForm()">
                                        </td>
                                        <td class="ac-input-td"></td>
                                    </tr>
                                </table>
                            </form>
                        </div>

                    </div>
                </div>

            </div>

        </div>
    </div>
</div>
<script type="text/javascript">
</script>
</body>
</html>